package faceQuestion;

import java.util.*;

/**
 * Description： TODO
 * Author： 王多鱼
 * CreateTime： 2021/6/29 18:44
 * 写一段代码，尝试在以下文本中搜索并打印出包含单词"your"
 * (不区分大小写)的句子，并按出现次序从高到低排序。
 **/
public class SearchYour {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        scanner.next();
        HashMap<String, Integer> hashMap = new HashMap<>();
        String str = null;
        while (!(str = scanner.nextLine()).equals("E0F")) {
            hashMap.put(str, getCount(str, "your"));
        }
        sort(hashMap);
    }

    //统计每行字符串这种“your”出现的次数
    private static Integer getCount(String str, String sub) {
        int count = 0;
        int start = 0;
        int temp = 0;
        String s = str.toLowerCase();
        while ((temp = s.indexOf(sub, start)) != -1) {
            count++;
            start = temp + sub.length();
        }
        return count;
    }

    //排序并降序输出
    private static void sort(HashMap<String, Integer> hashMap) {
        ArrayList<Map.Entry<String, Integer>> list = new ArrayList<>(hashMap.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o2.getValue() - o1.getValue();
            }
        });
        for (Map.Entry<String, Integer> e : list) {
            System.out.println(e.getKey() + "-->" + e.getValue());
        }
    }


}
